package com.cube.dp.adapter;

import com.cube.dp.adapter.fs.custom.CustomFileOperationServiceImpl;
import com.cube.dp.adapter.fs.third.IThirdPartyFileOperationService;
import com.cube.dp.adapter.fs.third.OssFileOperationServiceImpl;

/**
 * @author litb
 * @date 2022/5/21 17:12
 * <p>
 * 文件服务工厂
 */
public class FileOperationFactory {


    public static IThirdPartyFileOperationService getDefault() {
        return getInstance(EnumFileOperationType.DOUBLE_WRITE_AND_READ_FROM_CUSTOM);
    }

    /**
     * 获取对应的文件服务实例
     *
     * @param operationType 类型
     * @return 实例
     */
    public static IThirdPartyFileOperationService getInstance(EnumFileOperationType operationType) {
        switch (operationType) {
            case OSS:
                return new OssFileOperationServiceImpl();
            case CUSTOM:
                return new CustomFileOperationAdaptor(new CustomFileOperationServiceImpl());
            case DOUBLE_WRITE_AND_READ_FROM_CUSTOM:
                return new DoubleWriteAndReadCustomOperationAdaptor(new CustomFileOperationServiceImpl(),
                        new OssFileOperationServiceImpl());
            default:
                throw new IllegalArgumentException("storageType is not support");
        }
    }
}
